<?php
    class Mysql{
        private $connect;
        public function __construct($host,$uname,$pwd,$db,$port){
            $con=mysqli_connect($host,$uname,$pwd,$db,$port);
            mysqli_set_charset($con,'utf-8');
            if($con===false){
                die("数据库连接失败");
            }
            $this->connect=$con;
        }
        
        //命令执行的方法
        public function Query($sql){
            return $this->connect->query($sql);
        }
        //查询数据的方法 查询单条
        public function Find($sql){
            $data=[];
            $result=$this->connect->query($sql);
            if($result->num_rows>0){
                $data=$result->fetch_assoc();
            }
            return $data;
        }

        //查询多条数据
        public function Select($sql){
            $data=[];
            $result=$this->connect->query($sql);
            if($result->num_rows>0){
                for($i=0;$i<$result->num_rows;$i++){
                    $data[]=$result->fetch_assoc();
                }
            }
            return $data;
        }

        //删除记录的方法
        public function DeleteData($sql){
            return $this->connect->query($sql);
        }

        public function Cx($table,$field,$where){
            $sql="select ".$field." from ".$table." where ".$where;
            $result=$this->connect->query($sql);
            $data=[];
            for($i=0;$i<=$result->num_rows;$i++){
                $data[]=$result->fetch_assoc();
            }
            return array_filter($data);
        }



    }

    $mysql_connect=new Mysql('10.10.112.63','root','123456','2024','1000');
    //$user=$mysql_connect->Find("select * from abc_user where name='龙梦梅'");
    //$user=$mysql_connect->Select("select * from abc_user");
    $user=$mysql_connect->DeleteData("delete from abc_user where id=100");


    $a=$mysql_connect->Cx("abc_user",'name',"id=101");
    print_r($a);
    


?>